package de.haw.adt.implementation;

import static de.haw.adt.implementation.Values.KMH_IN_MS;
import de.haw.adt.interfaces.ISpeed;

class Speed extends AbstractPhysicalScalar implements ISpeed {

	private final double speed;
	
	private Speed(double speed) {
		this.speed = speed;
	}
	
	@Override
	double getValue() {
		return speed;
	}

	public int compareTo(ISpeed speed) {
		return Double.compare(this.getMs(), speed.getMs());
	}

	@Override
	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof Speed))
			return false;
		return this.compareTo((Speed) o) == 0;
	}


	public double getMs() {
		return speed;
	}

	public double getKmh() {
		return speed * KMH_IN_MS;
	}

	public ISpeed add(ISpeed speed) {
		return valueOf(this.getMs() + getMs());
	}

	public ISpeed sub(ISpeed speed) {
		return valueOf(this.getMs() - getMs());
	}
	
	public static ISpeed valueOf(double speed) {
		return new Speed(speed);
	}
}
